﻿using OestsCommon.Model;
using System;
using System.Collections.Generic;
using System.Data;

namespace OestsDataBase
{
    public class AreaDAL
    {
        //区域
        public static void CreateTable()
        {
            string sqlCheck = "if object_id( 'T_Area') is not null select 1 else select 0";
            if ((int)SqlHelper.ExecuteScalar(sqlCheck) == 0)
            {
                string sqlCreacte = @"CREATE TABLE T_Area (name NVARCHAR(50) primary key ,
                                describe NVARCHAR(MAX) not null)";

                SqlHelper.ExecuteNonQuery(sqlCreacte);
            }
        }
        public static List<AreaModel> GetData()
        {
            List<AreaModel> list = new List<AreaModel>();
            string strSql = "select * from T_Area";
            DataTable dt = SqlHelper.ExecuteDataTable(strSql);
            if (dt == null) { return null; }
            foreach (DataRow dr in dt.Rows)
            {
                AreaModel s = new AreaModel();
                s.Name = dr["name"].ToString();
                s.Describe = dr["describe"].ToString();

                bool b = false;
                Boolean.TryParse(dr["showMap"].ToString(), out b);
                s.ShowMap = b;

                bool bInventory = false;
                Boolean.TryParse(dr["showInventory"].ToString(), out bInventory);
                s.ShowInventory = bInventory;

                list.Add(s);
            }
            return list;

        }
    }
}
